package com.hxd.mall.module.usercenter.funs

import android.annotation.SuppressLint
import android.graphics.Color
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.hxd.mall.R
import com.hxd.mall.base.BaseInjectActivity
import com.hxd.mall.constant.HxdConstants.IntentParamsKeyDefine.person_info
import com.hxd.mall.constant.HxdConstantsRouterPath.PathUserCenter.path_user_center_funs_manager
import com.hxd.mall.module.usercenter.bean.Funsbean
import com.hxd.mall.module.usercenter.fragment.FunsFragmentAdapter
import com.hxd.mall.module.usercenter.home.PersonInfoBean
import com.hxd.mall.utils.local.fans_management_page_view
import com.hxd.mall.utils.local.sendPoint
import com.hxd.mall.utils.open.GsonUtil
import com.hxd.mall.utils.open.loadCircle
import com.hxd.mall.widget.TabBind
import crossoverone.statuslib.StatusUtil
import kotlinx.android.synthetic.main.activity_funs_manager_activity.*

/**
 * 粉丝管理页面
 */
@Route(path = path_user_center_funs_manager)
class FunsManagerActivity : BaseInjectActivity<IFunsManagerPresenter>(), IFunsManagerView {

    //viewpager 指示栏标题
    private lateinit var pagerIndicators: ArrayList<String>

    override fun attachLayoutRes(): Int = R.layout.activity_funs_manager_activity

    override fun initViews() {
        setTitleCommon(getString(R.string.funs_manager))
        buildPagerIndicator()
        initViewPager()
        //initListener()

        sendPoint(fans_management_page_view)
    }

    @SuppressLint("SetTextI18n")
    override fun initData() {
        val info = intent.getStringExtra(person_info) ?: ""
        if (!TextUtils.isEmpty(info)) {
            val infoBean = GsonUtil.json2bean(info, PersonInfoBean::class.java)

            infoBean.data.run {
                //昵称
                tv_nickName.text = userProfile.nickname
                //头像
                avator.loadCircle(userProfile.avatarUrl)
                //邀请码
                tv_code.text = "邀请码：${userProfile.code}"

                //粉丝数
                fun_num.text = "粉丝数：${userProfile.fansTotal}"
            }
        }
        //mPresenter?.getData(pageNum)
    }

    //接口数据回调
    override fun showData(t: Funsbean) {
        //if (null == t) return
    }

    override fun setStatusColor() {
        StatusUtil.setUseStatusBarColor(this, Color.WHITE)
    }

    override fun setSystemInvadeBlack() {
        StatusUtil.setSystemStatus(this, false, true)
    }

    private fun buildPagerIndicator() {
        pagerIndicators = ArrayList()

        TabBind(magicIndicator, viewPager, pagerIndicators)
    }

    private fun initViewPager() {
        viewPager.currentItem = 0
        viewPager.adapter = FunsFragmentAdapter(supportFragmentManager)
    }

}
